﻿
Imports System.IO

Namespace applicationInfoOutput
    Public Module applicationInfoOutput
        Public Const normalSuffix As String = ".log"
        Public Const criticalSuffix As String = ".critical.log"

        Private Function generateDefaultFilenameImpl() As String
#If Not (PocketPC OrElse Smartphone) Then
            Return applicationSign() + character.underline + envs.executingDirectory()
#Else
            return applicationSign()
#End If
        End Function

        'without suffix
        Public Function generateDefaultFilename(ByVal rootpath As String) As String
            Return combinepath(rootpath, _
                               applicationName(), _
                               generateDefaultFilenameImpl() + character.underline + _
                               shortTime(character.underline, character.minusSign, character.minusSign))
        End Function

        Public Sub generateFileStream(ByRef filestream As FileStream, _
                                      ByVal fileName As String, ByVal suffix As String, _
                                      ByVal NOFILEMARK As String)
            If Not filestream Is Nothing Then
                raiseError("close old filestream " + filestream.Name + _
                           ", and replace with new " + fileName + ", " + suffix, _
                           errorHandle.errorType.warning)
                closestream(filestream)
            End If

            On Error Resume Next
            If Not strsame(fileName, NOFILEMARK, True) Then
                fileName += suffix
                fixFileName(fileName)
                Dim dir As String = Nothing
                dir = fullpath(IO.Directory.GetCurrentDirectory + filesystem.directorySeperator + fileName)
                createDirectory(parentpath(fullpath(fileName)))
                filestream = New autoflushFileStream(fileName, IO.FileMode.Append _
                                                     , IO.FileAccess.Write, IO.FileShare.Read)
            Else
                filestream = Nothing
            End If
        End Sub
    End Module
End Namespace
